/*
 * @Description: 调序
 * @Author: Rfan
 * @Date: 2022-06-22 09:51:33
 * @LastEditTime: 2022-08-09 19:50:18
 */

import { useMemo, useState } from 'react';
import { useBoxMgtContext } from '../../../../contexts/BoxMgtContext';
import ReplaceRecordDialog from '../../ReplaceRecord';
import AutoFilingStateDialog from './AutoFilingState';

interface IFileOrderProps {
  info: any;
  selectItems: number[];
}

const AutoFiling = (props: IFileOrderProps) => {
  const { selectItems } = props;
  const { autoFilingFunc } = useBoxMgtContext();

  // 选择归档位置弹窗
  const [visible, setVisible] = useState(false);
  // 自动组卷状态弹窗
  const [filingVisible, setFilingVisible] = useState(false);

  const selectPlaceClose = (data?: any) => {
    setVisible(false);
    if (data) {
      console.log('selectPlaceClose', data);
      autoFilingFunc(data);
      setFilingVisible(true);
    }
  };

  return (
    <>
      <div
        onClick={() => {
          setVisible(true);
        }}
      >
        自动组卷
      </div>
      {useMemo(
        () => (
          <ReplaceRecordDialog
            visible={visible}
            type="filing"
            selectItems={selectItems}
            onClose={selectPlaceClose}
          />
        ),
        [visible]
      )}
      {useMemo(
        () => (
          <AutoFilingStateDialog
            visible={filingVisible}
            onClose={() => {
              setFilingVisible(false);
            }}
          />
        ),
        [filingVisible]
      )}
    </>
  );
};

export default AutoFiling;
